package com.edushare.common.mailer;

import java.text.SimpleDateFormat;

import com.edushare.common.util.URLUtils;
import com.edushare.common.vo.Assignments;
import com.edushare.common.vo.OutgoingEmails;
import com.edushare.common.vo.Users;

public class DeletedAssignment extends MailStringLoader {

	public DeletedAssignment(Users from, Users to, Assignments assgn){
		userTo = to;
		this.assgn = assgn;
		init(from, assgn);
	}
	
	private void init(Users from, Assignments assgn){
		replaceMap.put("FROM_USER_URL", URLUtils.getHomePageURL(from));
		replaceMap.put("FROM_USER_NAME",from.getCompleteUserName());
		replaceMap.put("ASSIGNMENT_NAME", assgn.getAssignmentTitle());
		replaceMap.put("ENTITY_URL", URLUtils.getHomePageURL(assgn.getCourseInstance().getCourse()));
		replaceMap.put("ENTITY_NAME",assgn.getCourseInstance().getCourse().getCourseName());
		messageString = templateParser(mailString, replaceMap);		
	}
	
	private Users userTo = null;
	private Assignments assgn = null;
	private String mailString = MailBase.get().stringMap.get(MailBase.DELETED_ASSIGNMENT_MAIL);
	
	@Override
	public OutgoingEmails send() {
		OutgoingEmails mail = new OutgoingEmails();
		mail.setContent(messageString);
		mail.setReceiverEmailId(userTo.getEmail());
		mail.setStatus(OutgoingEmails.EMAIL_TO_BE_SENT);
		mail.setCopyType(1);
		mail.setSubject("EduShare assignment \"" + assgn.getAssignmentTitle() + "\" cancelled");
		return mail;
	}
}
